
package com.assets.Adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.assets.R;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2019/5/7.
 */

public class Check_adapter extends BaseAdapter {
    private List<Map<String, Object>> data;
    private LayoutInflater layoutInflater;
    private Context context;
    public Check_adapter(Context context, List<Map<String, Object>> data) {
        //传入的data，就是我们要在listview中显示的信息
        this.context = context;
        this.data = data;
        this.layoutInflater = LayoutInflater.from(context);
    }
    public class Info {
        public TextView odd;//单号
        public TextView creator;//创建人
        public TextView sum;//盘点总数
        public TextView state;//状态
        public TextView scope;//盘点范围
        public TextView Date_created;//创建日期
        public TextView Inventory_date;//盘点日期
    }
    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position).get("state")+","+data.get(position).get("odd");
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Info info = new Info();
        convertView = layoutInflater.inflate(R.layout.check_adapter, null);
        info.odd = (TextView) convertView.findViewById(R.id.odd);
        info.creator = (TextView) convertView.findViewById(R.id.creator);
        info.Date_created = (TextView) convertView.findViewById(R.id.Date_created);
        info.Inventory_date = (TextView) convertView.findViewById(R.id.Inventory_date);
        info.scope = (TextView) convertView.findViewById(R.id.scope);
        info.state = (TextView) convertView.findViewById(R.id.state);
        info.sum = (TextView) convertView.findViewById(R.id.sum);
        //设置数据
        info.odd.setText((String) data.get(position).get(
                "odd"));
        info.creator.setText((String) data.get(position).get(
                "creator"));
        info.Date_created.setText((String) data.get(position)
                .get("Date_created"));
        info.Inventory_date.setText((String) data.get(position)
                .get("Inventory_date"));
        info.scope.setText((String) data.get(position)
                .get("scope") == null ? "" : (String) data.get(position)
                .get("scope"));
        /**
         if (status.equals("0")) {
         this.status = "未开始";
         }else if (status.equals("1")) {
         this.status = "进行中";
         }else if (status.equals("2")) {
         this.status = "已完成";
         }
         }
         */
        String myState = data.get(position).get("state").toString();
        Log.d("0是什么", "myState: " + myState);
        if ("0".equals(myState)) {
            info.state.setText("未开始");
        }else if ("1".equals(myState)) {
            info.state.setText("进行中");
        }else if ("2".equals(myState)) {
            info.state.setText("已完成");
        }else {
            info.state.setText("未知状态");
        }
//        info.state.setText((String) data.get(position)
//                .get("state"));
        info.sum.setText((String) data.get(position)
                .get("sum"));
        return convertView;
    }
}

/*
package com.assets.Adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.assets.R;

import java.util.List;
import java.util.Map;

*/
/**
 * Created by Administrator on 2019/5/7.
 *//*


public class Check_adapter extends BaseAdapter {
    private List<Map<String, Object>> data;
    private LayoutInflater layoutInflater;
    private Context context;
    public Check_adapter(Context context, List<Map<String, Object>> data) {
        //传入的data，就是我们要在listview中显示的信息
        this.context = context;
        this.data = data;
        this.layoutInflater = LayoutInflater.from(context);
    }
    public class Info {
        public TextView odd;//单号
        public TextView creator;//创建人
        public TextView sum;//盘点总数
        public TextView state;//状态
        public TextView scope;//盘点范围
        public TextView Date_created;//创建日期
        public TextView Inventory_date;//盘点日期
    }
    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position).get("state")+","+data.get(position).get("odd");
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
       Info info = new Info();
        convertView = layoutInflater.inflate(R.layout.check_adapter, null);
        info.odd = (TextView) convertView.findViewById(R.id.odd);
        info.creator = (TextView) convertView.findViewById(R.id.creator);
        info.Date_created = (TextView) convertView.findViewById(R.id.Date_created);
        info.Inventory_date = (TextView) convertView.findViewById(R.id.Inventory_date);
        info.scope = (TextView) convertView.findViewById(R.id.scope);
        info.state = (TextView) convertView.findViewById(R.id.state);
        info.sum = (TextView) convertView.findViewById(R.id.sum);
        //设置数据
        info.odd.setText(data.get(position).get(
                "odd") + "");
        info.creator.setText((String) data.get(position).get(
                "creator"));
        info.Date_created.setText((String) data.get(position)
                .get("Date_created"));
        info.Inventory_date.setText((String) data.get(position)
                .get("Inventory_date"));
        info.scope.setText((String) data.get(position)
                .get("scope"));
        */
/**
             if (status.equals("0")) {
                this.status = "未开始";
            }else if (status.equals("1")) {
                this.status = "进行中";
            }else if (status.equals("2")) {
                this.status = "已完成";
            }
            }
         *//*

        String myState = data.get(position).get("state").toString();
        Log.d("0是什么", "myState: " + myState);
        if ("0".equals(myState)) {
            info.state.setText("未开始");
        }else if ("1".equals(myState)) {
            info.state.setText("进行中");
        }else if ("2".equals(myState)) {
            info.state.setText("已完成");
        }else {
            info.state.setText("未知状态");
        }
//        info.state.setText((String) data.get(position)
//                .get("state"));
        info.sum.setText("" + data.get(position)
                .get("sum"));
        return convertView;
    }
}
*/
